<?php

// +----------------------------------------------------------------------
// | 版权所有 2017-2027 云南环拓科技有限公司，并保留所有权利。
// +----------------------------------------------------------------------
// | Copyright (c) 2017-2027 http://www.yn123.com All rights reserved.
// +----------------------------------------------------------------------
// | Notice: This code is not open source, it is strictly prohibited
// |         to distribute the copy, otherwise it will pursue its
// |         legal responsibility.
// | 注意：  这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用,
// |        不允许对程序代码以任何形式任何目的的再发布。
// +----------------------------------------------------------------------
// | Author: feraner <feraner@163.com> 
// | Date: 2019/12/24
// +----------------------------------------------------------------------

namespace app\common\services\wechattemplate;

use app\common\facade\Arr;
use app\common\services\WechatTemplateService;
use think\Db;

/**
 *
 * Class WechatPayTemplateService
 * @package app\common\services\wechattemplate
 * @author feraner<feraner@163.com>
 * @date 2019/12/24
 */
class WechatPayTemplateService extends WechatTemplateService
{


    public function __construct()
    {
        parent::__construct();
    }


    /**
     * 充值发布豆成功 -- 通知用户
     * @param $chargeInfo
     *
     * @return bool
     * @throws \WeChat\Exceptions\InvalidResponseException
     * @throws \WeChat\Exceptions\LocalCacheException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function sendBuyBeanOk($chargeInfo)
    {
        $buyUserInfo = Db::name('user')
            ->where('id', Arr::get($chargeInfo, 'user_id', 0))
            ->find() ?: [];
        if ($buyUserInfo) {
            $this->clearSetData()
                ->set('template', 'recharge_success')
                ->set('url', 'index/Userwallet/beanRecord?type=1')
                ->set('first', '尊敬的用户，您已成功购买汇豆')
                ->set('keyword1', Arr::get($buyUserInfo, 'truename', Arr::get($buyUserInfo, 'name')))
                ->set('keyword2', Arr::get($chargeInfo, 'money', 0))
                ->set('keyword3', Arr::get($chargeInfo, 'order_no'))
                ->set('keyword4', date('Y-m-d H:i', Arr::get($chargeInfo, 'created_at', time())))
                ->set('remark', '本次共购买' . Arr::get($chargeInfo, 'bean', 0) . '个汇豆,我们竭力为您提供优质服务！')
                ->set('toUser', Arr::get($buyUserInfo, 'wechat_openid'))
                ->send();
        }
        return true;
    }


    /**
     * 提醒购买人支付提醒 -- 提醒支付消息通知
     * @param $chargeInfo
     *
     * @return bool
     * @throws \WeChat\Exceptions\InvalidResponseException
     * @throws \WeChat\Exceptions\LocalCacheException
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     */
    public function remindPayMoney($chargeInfo)
    {
        return true;
        $buyUserInfo = Db::name('user')
            ->where('id', Arr::get($chargeInfo, 'user_id', 0))
            ->find() ?: [];
        if ($buyUserInfo) {
            $this->clearSetData()
                ->set('template', 'remind_pay')
                ->set('url', 'index/Userwallet/wechatPay?chargeId=' . Arr::get($chargeInfo, 'id'))
                ->set('first', '您好，您有一笔充值订单未支付，请及时支付')
                ->set('keyword1', '充值购买汇豆')
                ->set('keyword2', Arr::get($chargeInfo, 'bean'))
                ->set('keyword3', '1元 = ' . sysconf('publish_job_bean_rate') . '个汇豆')
                ->set('keyword4', Arr::get($chargeInfo, 'money') . '元')
                ->set('keyword5', date('Y-m-d H:i', Arr::get($chargeInfo, 'created_at')))
                ->set('remark', '订单超过 6小时未支付将自动取消，给您带来不便敬请谅解!')
                ->set('toUser', Arr::get($buyUserInfo, 'wechat_openid'))
                ->send();
        }
        return true;

    }



}
